package lancooUpLoad;

import com.example.lancooznbk.presenter.PaperDef;
import com.example.lancooznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import testPaperCTCS.GuessTestingPaperActivity;
import testPaperJBFX.BasicReviewPaperActivity;
import testPaperNDFX.DifficultReviewPaperActivity;
import testPaperWrong.WrongQuesPaperActivity;
import testPaperWrongHistory.HistoryWrongQuesPaperActivity;

/**
 * Created by Administrator on 2017/9/11/011.
 */

public class ChangeStuFavouritePresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;
    private int ModelFrom;
    private boolean isFromExit = false;

    public ChangeStuFavouritePresenter(ILoadPaperView view, int modelFrom) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
    }

    @Override
    public void getData(boolean isShowLoading) {
        //  if (isShowLoading) view.showLoading();
        HttpOnNextListener<ChangeStuFavouriteEntityResult> httpOnNextListener = new HttpOnNextListener<ChangeStuFavouriteEntityResult>() {


            @Override
            public void onNext(ChangeStuFavouriteEntityResult favourite) {
                if(favourite.getValue().equals("1")){
//                    ToastUtils.showShort("操作成功");
//                        new Handler().postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//                            }
//                        },600);
//                    }
                }else{
                    ToastUtils.showShort("收藏失败!结果信息为："+favourite.getValue());
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        };

        ChangeStuFavouriteParam api = null;
        if(ModelFrom == PaperDef.FROM_BASE_REVIEW) {
            api = new ChangeStuFavouriteParam(httpOnNextListener, (BasicReviewPaperActivity)view);
        }else if(ModelFrom == PaperDef.FROM_DIFFERENT_REVIEW){
            api = new ChangeStuFavouriteParam(httpOnNextListener, (DifficultReviewPaperActivity)view);
        }else if(ModelFrom == PaperDef.FROM_GUESS_REVIEW){
            api = new ChangeStuFavouriteParam(httpOnNextListener, (GuessTestingPaperActivity)view);
        }else if(ModelFrom == PaperDef.FROM_BASE_REVIEW_WRONG||ModelFrom == PaperDef.FROM_DIFFERENT_REVIEW_WRONG){
            api = new ChangeStuFavouriteParam(httpOnNextListener, (WrongQuesPaperActivity)view);
        }else if(ModelFrom==PaperDef.FROM_BASE_REVIEW_WRONG_History||ModelFrom==PaperDef.FROM_DIFFERENT_REVIEW_WRONG_History){
            api = new ChangeStuFavouriteParam(httpOnNextListener, (HistoryWrongQuesPaperActivity)view);
        }

        api.setChangeStuFavouriteModel(DataPackage.GetChangeStuFavouriteModel(UserInfo.StuId,UserInfo.SubjectId,UserInfo.StageNo,
                PaperInfor.QuesBrief,PaperInfor.QuesID,PaperInfor.TypeID,PaperInfor.IsLike));
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    public void getData(boolean isShowing ,boolean isFromExit){
        this.isFromExit = isFromExit;
        getData(isShowing);
    }

}